package com.shi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shi.entity.dto.SysLogPageDto;
import com.shi.entity.po.SysLog;
import com.shi.entity.vo.PageVO;
import com.shi.mapper.SysLogMapper;
import com.shi.service.SysLogService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 系统日志(SysLog)表服务实现类
 *
 * @author makejava
 * @since 2024-06-02 18:47:56
 */
@Service("sysLogService")
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public PageVO page(SysLogPageDto sysLogPageDto) {
        // 模糊字段
        String likeKey = sysLogPageDto.getLike();
        // 起始时间
        Date startTime = sysLogPageDto.getStartTime();
        // 结束时间
        Date endTime = sysLogPageDto.getEndTime();
        Page<SysLog> mpPage = sysLogPageDto.toMPPageOrderByCreateTime(SysLog.class);
        LambdaQueryWrapper<SysLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(i -> i.like(SysLog::getMethodSignature, likeKey).or().like(SysLog::getRequestUri, likeKey))
                .and(startTime != null || endTime != null, i -> i.ge(startTime != null, SysLog::getCreateTime, startTime).le(endTime != null, SysLog::getCreateTime, endTime));
        page(mpPage, queryWrapper);
        return PageVO.of(mpPage);
    }
}

